package com.ruoyi.web.controller.noauth;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.api.domain.ApiManage;
import com.ruoyi.api.service.IApiManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * api服务管理Controller
 *
 * @author ruoyi
 * @date 2025-08-06
 */
@RestController
@RequestMapping("/noAuth/api/manage")
public class NoAuthApiManageController extends BaseController
{
    @Autowired
    private IApiManageService apiManageService;

    /**
     * 查询api服务管理列表
     */

    @GetMapping("/list")
    public TableDataInfo list(ApiManage apiManage)
    {
        startPage();
        List<ApiManage> list = apiManageService.selectApiManageList(apiManage);
        return getDataTable(list);
    }

    /**
     * 导出api服务管理列表
     */
    @PreAuthorize("@ss.hasPermi('api:manage:export')")
    @Log(title = "api服务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiManage apiManage)
    {
        List<ApiManage> list = apiManageService.selectApiManageList(apiManage);
        ExcelUtil<ApiManage> util = new ExcelUtil<ApiManage>(ApiManage.class);
        util.exportExcel(response, list, "api服务管理数据");
    }

    /**
     * 获取api服务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:manage:query')")
    @GetMapping(value = "/{apiId}")
    public AjaxResult getInfo(@PathVariable("apiId") Long apiId)
    {
        return success(apiManageService.selectApiManageByApiId(apiId));
    }

    /**
     * 新增api服务管理
     */
    @PreAuthorize("@ss.hasPermi('api:manage:add')")
    @Log(title = "api服务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApiManage apiManage)
    {
        return toAjax(apiManageService.insertApiManage(apiManage));
    }

    /**
     * 修改api服务管理
     */
    @PreAuthorize("@ss.hasPermi('api:manage:edit')")
    @Log(title = "api服务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApiManage apiManage)
    {
        return toAjax(apiManageService.updateApiManage(apiManage));
    }

    /**
     * 删除api服务管理
     */
    @PreAuthorize("@ss.hasPermi('api:manage:remove')")
    @Log(title = "api服务管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{apiIds}")
    public AjaxResult remove(@PathVariable Long[] apiIds)
    {
        return toAjax(apiManageService.deleteApiManageByApiIds(apiIds));
    }
}
